package com.wc.算法提高课.C第三章_图论.二分图.捉迷藏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/23 4:06
 * @description https://www.acwing.com/problem/content/381/
 */
public class Main {
    /**
     * 思路： 最大独立集问题, 因为A能走到B就代表A可以看到B, 相当于A -> B连接了一条边, 用传递闭包连边, 用匈牙利算
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 210;
    static boolean[][] g = new boolean[N][N];
    static boolean[] st = new boolean[N];
    static int[] match = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            g[a][b] = true;
        }
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    g[i][j] |= g[i][k] && g[k][j];
                }
            }
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            Arrays.fill(st, false);
            if (find(i)) res++;
        }
        out.println(n - res);
        out.flush();
    }

    static boolean find(int u) {
        for (int i = 1; i <= n; i++) {
            if (st[i] || !g[u][i]) continue;
            st[i] = true;
            int t = match[i];
            if (t == 0 || find(t)) {
                match[i] = u;
                return true;
            }
        }
        return false;
    }

    static class Pair implements Comparable<Pair> {
        int x, y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
